<template>

    <div>
        <h1>这是登录页面</h1>
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="账号">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">登录</el-button>
        </el-form-item>
      </el-form>
    </div>

</template>


<script>
import {userLogin} from "@/api/userApi";

export default {
  data() {
    return {
      form: {
        username: '',
        password: ''
      }
    }
  },
  methods: {
    onSubmit() {
      userLogin(this.form).then(res => {
        console.log(res);
        if(res.data.flag){
          this.$message.success("登录成功");
          localStorage.setItem('token',res.data.data);
          this.$router.push('/list');
        }else{
          this.$message.error(res.data.msg);
        }

      })
      console.log('submit!');
    }
  }
}
</script>

<style scoped>

</style>